using System;
using System.Collections.Generic;

namespace Common.Core
{
	public class SingletonProvider
	{
		private static readonly IDictionary<Type, object> objects = new Dictionary<Type, object>();

		public static T Get<T>() where T : new()
		{
			if(!objects.ContainsKey(typeof(T)))
			{
				lock (objects)
				{
					if(!objects.ContainsKey(typeof(T)))
					{
						objects[typeof (T)] = new T();
					}
				}
			}

			return (T) objects[typeof (T)];
		}
	}
}